package com.bhs.sansong.ui.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bhs.sansong.R;
import com.bhs.sansong.utils.MyUtils;
import com.lxj.xpopup.core.BottomPopupView;

/**
 * 打电话2
 */
public class BottomSelectPhone2Dialog extends BottomPopupView implements View.OnClickListener {

    private TextView mTvPrincipal;
    private TextView mTvLandlinePhone;
    private LinearLayout mLlShipmentTracking;
    private LinearLayout mLlLandlinePhone;
    private TextView mTvShipmentTracking;
    private final String Principal;
    private final String LandlinePhone;
    private final String ShipmentTracking;

    public BottomSelectPhone2Dialog(@NonNull Context context, String Principal, String LandlinePhone, String ShipmentTracking) {
        super(context);
        this.Principal = Principal;
        this.LandlinePhone = LandlinePhone;
        this.ShipmentTracking = ShipmentTracking;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
        mTvPrincipal.setText(Principal);

        if (!TextUtils.isEmpty(ShipmentTracking)) {
            mTvShipmentTracking.setText(ShipmentTracking);
        } else {
            mLlShipmentTracking.setVisibility(GONE);
        }
        if (!TextUtils.isEmpty(LandlinePhone)) {
            mTvLandlinePhone.setText(LandlinePhone);
        } else {
            mLlLandlinePhone.setVisibility(GONE);
        }
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View view) {
        dismiss();
        switch (view.getId()) {
            case R.id.ll_principal:
                MyUtils.callPhone(getContext(), Principal);
                break;
            case R.id.ll_landline_phone:
                MyUtils.callPhone(getContext(), LandlinePhone);
                break;
            case R.id.ll_shipment_tracking:
                MyUtils.callPhone(getContext(), ShipmentTracking);
                break;
        }
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_bottom_select_phone2;
    }

    private void initView() {
        findViewById(R.id.ll_principal).setOnClickListener(this);
        mTvPrincipal = findViewById(R.id.tv_principal);
        mLlLandlinePhone = findViewById(R.id.ll_landline_phone);
        mLlLandlinePhone.setOnClickListener(this);
        mTvLandlinePhone = findViewById(R.id.tv_landline_phone);
        mLlShipmentTracking = findViewById(R.id.ll_shipment_tracking);
        mLlShipmentTracking.setOnClickListener(this);
        mTvShipmentTracking = findViewById(R.id.tv_shipment_tracking);
        findViewById(R.id.tv_cancel).setOnClickListener(this);
    }
}
